package observer.swing;

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class SwingObserverExample{
	JFrame frame;

	public static void main(String[] args){
		SwingObserverExample example = new SwingObserverExample();
		example.go();
	}

	public void go(){
		frame = new JFrame();
		JButton button = new JButton("Should I do it?");

		// With lambdas
		button.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				System.out.println("Don't do it, you might regret it!");
			}
		});

		button.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				System.out.println("Come on, do it!");
			}
		});
		// frame.getContentPane().add(BorderLayout.CENTER, button);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Set frame properties
		frame.getContentPane().add(BorderLayout.CENTER, button);
		frame.setSize(300, 300);
		frame.setVisible(true);
	}
}